home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume10 / comobj.lisp / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-07-30  |  49.2 KB

  1. Path: uunet!rs
  2. From: rs@uunet.UU.NET (Rich Salz)
  3. Newsgroups: comp.sources.unix
  4. Subject: v10i077:  Common Objects, Common Loops, Common Lisp, Part03/13
  5. Message-ID: <744@uunet.UU.NET>
  6. Date: 31 Jul 87 19:58:53 GMT
  7. Organization: UUNET Communications Services, Arlington, VA
  8. Lines: 1464
  9. Approved: rs@uunet.UU.NET
  10.  
  11. Submitted-by: Roy D'Souza <dsouza%hplabsc@hplabs.HP.COM>
  12. Posting-number: Volume 10, Issue 77
  13. Archive-name: comobj.lisp/Part03
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then unpack
  17. # it by saving it into a file and typing "sh file".  To overwrite existing
  18. # files, type "sh file -c".  You can also feed this as standard input via
  19. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  20. # will see the following message at the end:
  21. #        "End of archive 3 (of 13)."
  22. # Contents:  co-meta.l defsys.l fixup.l high.l
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'co-meta.l' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'co-meta.l'\"
  26. else
  27. echo shar: Extracting \"'co-meta.l'\" \(12006 characters\)
  28. sed "s/^X//" >'co-meta.l' <<'END_OF_FILE'
  29. X
  30. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. X;
  32. X; File:         co-meta.l
  33. X; RCS:          $Revision: 1.1 $
  34. X; SCCS:         %A% %G% %U%
  35. X; Description:  Metaclass for CommonObjects
  36. X; Author:       James Kempf
  37. X; Created:      March 10, 1987
  38. X; Modified:     March 10, 1987  13:30:58 (Roy D'Souza)
  39. X; Language:     Lisp
  40. X; Package:      COMMON-OBJECTS
  41. X; Status:       Distribution
  42. X;
  43. X; (c) Copyright 1987, HP Labs, all rights reserved.
  44. X;
  45. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. X;
  47. X; Copyright (c) 1987 Hewlett-Packard Corporation. All rights reserved.
  48. X;
  49. X; Use and copying of this software and preparation of derivative works based
  50. X; upon this software are permitted.  Any distribution of this software or
  51. X; derivative works must comply with all applicable United States export
  52. X; control laws.
  53. X; 
  54. X; This software is made available AS IS, and Hewlett-Packard Corporation makes
  55. X; no warranty about the software, its performance or its conformity to any
  56. X; specification.
  57. X;
  58. X; Suggestions, comments and requests for improvement may be mailed to
  59. X; aiws@hplabs.HP.COM
  60. X
  61. X;;;-*-Mode:LISP; Package:(CO (PCL LISP)); Base:10; Syntax: Common-lisp-*-
  62. X;;;
  63. X;;; *************************************************************************
  64. X;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  65. X;;;
  66. X;;; Use and copying of this software and preparation of derivative works
  67. X;;; based upon this software are permitted.  Any distribution of this
  68. X;;; software or derivative works must comply with all applicable United
  69. X;;; States export control laws.
  70. X;;; 
  71. X;;; This software is made available AS IS, and Xerox Corporation makes no
  72. X;;; warranty about the software, its performance or its conformity to any
  73. X;;; specification.
  74. X;;; 
  75. X;;; Any person obtaining a copy of this software is requested to send their
  76. X;;; name and post office or electronic mail address to:
  77. X;;;   CommonLoops Coordinator
  78. X;;;   Xerox Artifical Intelligence Systems
  79. X;;;   2400 Hanover St.
  80. X;;;   Palo Alto, CA 94303
  81. X;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  82. X;;;
  83. X;;; Suggestions, comments and requests for improvements are also welcome.
  84. X;;; *************************************************************************
  85. X
  86. X(in-package 'common-objects :nicknames '(co) :use '(lisp pcl walker))
  87. X
  88. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  89. X; 
  90. X;    CommonObjects Class Ndefstruct
  91. X;
  92. X;  Instances are represented as trees of their parent instances just like
  93. X;  in the original CommonObjects implementation except that we do not make
  94. X;  make the single inheritance optimization of in-lining the first parent.
  95. X;  The first slot of every instance is the class object.
  96. X;  The second slot of every instance is named .SELF. and is a pointer to
  97. X;  the acutal object. Then come slots for each of the parent class instances,
  98. X;  then the slots for this class.
  99. X;
  100. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  101. X
  102. X(ndefstruct (common-objects-class
  103. X          (:class class)
  104. X          (:include (essential-class))    
  105. X          (:conc-name class-)
  106. X            )
  107. X
  108. X  (instance-size 1)             ;The total number of slots every instance
  109. X                ;of this class must have.  This includes
  110. X                ;one slot for the pointer to outer self and
  111. X                ;one slot for each of the parent instances.
  112. X
  113. X  (local-super-slot-names ())   ;A list of the names of the slots used to
  114. X                ;store the parent instances.  This list
  115. X                ;exactly parallels the local-supers as
  116. X                ;stored in class-local-supers.
  117. X
  118. X  (slots ())            ;The slots required by CommonLoops.
  119. X
  120. X  (user-visible-slots ())    ;Instance variable names.
  121. X
  122. X  (children ())            ;Children of this guy. Not currently used.
  123. X
  124. X  (init-keywords                ;Initialization keywords
  125. X    () 
  126. X  )        
  127. X  (init-keywords-check T)       ;Whether to check the initialization 
  128. X                ;keywords
  129. X) ;end ndefstruct for common-objects-class
  130. X
  131. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  132. X;  Establishment of the CommonObjects MetaClass
  133. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  134. X(eval-when (load)
  135. X (define-meta-class common-objects-class 
  136. X   (lambda (x) (%instance-ref x $CLASS-OBJECT-INDEX))
  137. X))
  138. X
  139. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  140. X;  CommonObjects MetaClass Protocol  
  141. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  142. X
  143. X;;add-class-Add a CommonObjects class. Part of the metaclass protocol.
  144. X
  145. X(defmeth add-class ((class common-objects-class)
  146. X            new-local-supers
  147. X            new-local-slots
  148. X            extra
  149. X                   )
  150. X
  151. X  (let 
  152. X    ( 
  153. X      (local-super-slot-names
  154. X      (mapcar #'(lambda (nls) (local-super-slot-name (class-name nls)))
  155. X          new-local-supers
  156. X          )
  157. X       )
  158. X     )
  159. X
  160. X    (setf (class-local-super-slot-names class) local-super-slot-names)
  161. X
  162. X    (setf (class-user-visible-slots class) new-local-slots)
  163. X
  164. X    (setq new-local-slots 
  165. X          (mapcar #'(lambda (x) (make-slotd class :name x))
  166. X                    (append local-super-slot-names
  167. X                        new-local-slots)
  168. X          )
  169. X    )
  170. X
  171. X    (setf (class-instance-size class) (length new-local-slots))
  172. X
  173. X    (run-super)
  174. X
  175. X  ) ;let
  176. X
  177. X) ;end add-class
  178. X
  179. X;;class-slots-Return the slot names for the parents
  180. X
  181. X(defmeth class-slots ((class common-objects-class))
  182. X
  183. X  (class-local-slots class)
  184. X
  185. X) ;end class-slots
  186. X
  187. X;;has-slot-p-Return T if class has user visible slot symbol
  188. X
  189. X(defmeth has-slot-p ((class common-objects-class) symbol)
  190. X
  191. X  (let
  192. X    (
  193. X      (bool NIL)
  194. X    )
  195. X
  196. X    (dolist (slotd (class-user-visible-slots class))
  197. X      (when  (equal symbol (slot-name-from-slotd slotd))
  198. X    (setf bool T)
  199. X        (return)
  200. X      )
  201. X    )
  202. X    bool
  203. X
  204. X  ) ;end let
  205. X
  206. X) ;end has-slot-p
  207. X
  208. X;;init-keywords-Return the initialization keywords
  209. X
  210. X(defmeth init-keywords ((class common-objects-class))
  211. X
  212. X  (class-init-keywords class)
  213. X
  214. X) ;init-keywords
  215. X
  216. X;;class-local-super-names-Return the names of the local supers for
  217. X;;  this class.
  218. X
  219. X(defmeth class-local-super-names ((class common-objects-class))
  220. X
  221. X  (mapcar #'(lambda (x) (class-name x)) (class-local-supers class))
  222. X
  223. X) ;end class-local-super-names
  224. X
  225. X;;compute-class-precedence-list-Calculate class precedence.
  226. X;;  CommonObjects classes don't inherit in the CommonLoops sense.  
  227. X;;  Tell CommonLoops that they only inherit from themselves, 
  228. X;;  the class COMMON-OBJECTS-CLASS itself which they need for 
  229. X;;  GET-SLOT-USING-CLASS and PUT-SLOT-USING-CLASS and default printing
  230. X;;  to work right.
  231. X
  232. X(defmeth compute-class-precedence-list ((class common-objects-class))
  233. X
  234. X  (list class (class-named 'common-objects-class) (class-named 'object))
  235. X
  236. X) ;end compute-class-precedence-list
  237. X
  238. X;;method-alist-Return the a-list of names v.s. method objects. Only
  239. X;;  methods which are CommonObjects methods are returned. This
  240. X;;  is to accomodate system generated methods, like TYPE-OF, which
  241. X;;  should not be identified as methods on CommonObjects instances.
  242. X;;  This routine is primarily used in parsing.
  243. X
  244. X(defmeth method-alist ((class common-objects-class))
  245. X  (declare (special *universal-methods*))
  246. X
  247. X  (let
  248. X    (
  249. X      (alist NIL)
  250. X    )
  251. X
  252. X    ;;First get the direct methods
  253. X
  254. X    (dolist (methobj (class-direct-methods class))
  255. X
  256. X        (if (eq (class-name (class-of methobj)) 'common-objects-method)
  257. X
  258. X          (push 
  259. X        (list (unkeyword-standin (method-name methobj)) methobj)
  260. X        alist
  261. X      )
  262. X        ) ;if
  263. X    )
  264. X
  265. X    ;;Now check if any of the universal methods need to be added
  266. X
  267. X    (dolist (univmeth *universal-methods*)
  268. X
  269. X      (if (not (assoc univmeth alist))
  270. X        (push
  271. X          (list 
  272. X        univmeth 
  273. X        (find-method 
  274. X          (discriminator-named (keyword-standin univmeth))
  275. X              '(common-objects-class)
  276. X          NIL
  277. X          T
  278. X            )
  279. X          )
  280. X          alist
  281. X        )
  282. X
  283. X      ) ;if
  284. X
  285. X    ) ;dolist            
  286. X
  287. X    alist
  288. X
  289. X  ) ;end let
  290. X
  291. X) ;end method-alist
  292. X
  293. X;;check-init-keywords-Check if the initialization keywords are
  294. X;;  correct
  295. X
  296. X(defmeth check-init-keywords ((class common-objects-class) keylist)
  297. X
  298. X  (let
  299. X    (
  300. X      (legalkeys (class-init-keywords class))
  301. X    )
  302. X    
  303. X    (do
  304. X      (
  305. X        (key (car keylist) (cddr key) )
  306. X      )
  307. X      ( (null key) )
  308. X
  309. X      (if (not (and (keywordp (car key)) (>= (length key) 2)))
  310. X        (error "MAKE-INSTANCE: For type ~S, keylist must have alternating keys and values. List:~S~%"
  311. X         (class-name class) (car keylist)
  312. X        )
  313. X      )
  314. X
  315. X      (when (not (member (car key) legalkeys))
  316. X        (error "MAKE-INSTANCE: For type ~S, ~S is not a legal initialization keyword.~%"
  317. X         (class-name class) (car key)
  318. X        )
  319. X      )
  320. X    ) ;dolist
  321. X
  322. X  ) ;let
  323. X
  324. X) ;end check-init-keywords
  325. X
  326. X;;optimize-get-slot-Optimize a get slot by returning
  327. X;;  the right code. CommonObjects instances are statically
  328. X;;  allocated, so "hard" indicies can be used for them.
  329. X;;  Stolen from the protocol for BASIC-CLASS.
  330. X
  331. X;(defmeth optimize-get-slot ((method common-objects-method)
  332. X;                     (class common-objects-class)
  333. X;                     form)
  334. X;  (declare (ignore method)) ; rds 3/9
  335. X(defmeth optimize-get-slot ((class common-objects-class) form)
  336. X    `(%instance-ref ,(second form) ,(slot-index class (second (third form))))
  337. X
  338. X
  339. X
  340. X) ;end optimize-get-slot
  341. X
  342. X;;pcl::optimize-setf-of-get-slot-Optimize a setf of a slot
  343. X;;  by returning the right code. Again, "hard" indicies
  344. X;;  can be used since in-line allocation is the rule.
  345. X;;  Stolen from the protocol for BASIC-CLASS.
  346. X
  347. X;(defmeth pcl::optimize-setf-of-get-slot ((method common-objects-method)
  348. X;                         (class common-objects-class)
  349. X;                         form)
  350. X;  (declare (ignore method))
  351. X(defmeth pcl::optimize-setf-of-get-slot ((class common-objects-class)
  352. X                                         form)
  353. X    `(setf 
  354. X      (%instance-ref , (nth 1 form) ,(slot-index class (second (nth 2 form))))
  355. X           ,(nth 3 form)
  356. X     )
  357. X
  358. X) ;end optimize-setf-of-get-slot
  359. X
  360. X;;slot-index-Calculate the slot index for the indicated slot
  361. X
  362. X(defmeth slot-index ((class common-objects-class) slotname)
  363. X
  364. X  ;;Treat .SELF. as a special case
  365. X
  366. X  (if (eq slotname '.self.)
  367. X    $SELF-INDEX
  368. X
  369. X    (calculate-slot-index 
  370. X      slotname
  371. X      (class-local-super-slot-names class) 
  372. X      (class-user-visible-slots class)
  373. X    )
  374. X
  375. X  ) ;if
  376. X
  377. X) ;end slot-index
  378. X
  379. X;;get-slot-using-class-Generic version for all CommonObjects classes.
  380. X;;  Normally, this will be optimized out by the optimization method
  381. X;;  but just in case.
  382. X
  383. X(defmeth get-slot-using-class ((class common-objects-class) object slot-name)
  384. X
  385. X  (%instance-ref object (slot-index class slot-name))
  386. X
  387. X) ;get-slot-using-class 
  388. X
  389. X;;put-slot-using-class-Generic version for all CommonObjects classes.
  390. X;;  A bug in the default code-walker makes this necessary, although
  391. X;;  ultimately a custom walking function for CommonObjects methods
  392. X;;  might make the optimization work. Note that the code walker
  393. X;;  bug is fixed in the specialized walker method WALK-METHOD-BODY-INTERNAL
  394. X;;  for CommonObjects methods.
  395. X
  396. X(defmeth pcl::put-slot-using-class 
  397. X  ((class common-objects-class) object slot-name new-value)
  398. X
  399. X  (setf 
  400. X    (%instance-ref object (slot-index class slot-name) )
  401. X    new-value
  402. X  )
  403. X  
  404. X) ;put-slot-using-class
  405. X
  406. X
  407. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  408. X;  CommonObjects MetaClass Utility Functions
  409. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  410. X
  411. X;;defined-classes-List the defined CommonObjects classes
  412. X
  413. X(defun defined-classes ()
  414. X
  415. X  (let 
  416. X    (
  417. X      (defined-types NIL)
  418. X      (class (class-named 'common-objects-class))
  419. X    )
  420. X
  421. X    (maphash 
  422. X    #'(lambda (key val) 
  423. X        (when (and val (eq (class-of val) class))
  424. X          (setf defined-types (cons key defined-types))
  425. X            )
  426. X      )
  427. X          pcl::*class-name-hash-table*
  428. X    )
  429. X    defined-types
  430. X  )
  431. X) ;end defined-classes
  432. X
  433. X;;slot-name-from-slotd-Return the name of the slot, given the SLOTD.
  434. X
  435. X(defun slot-name-from-slotd (slotd)
  436. X  slotd
  437. X
  438. X) ;slot-name-from-slotd
  439. X
  440. X;;method-name-Return the method name, given the method object
  441. X
  442. X(defun method-name (methobj)
  443. X
  444. X  (discriminator-name (method-discriminator methobj))
  445. X)
  446. X
  447. END_OF_FILE
  448. if test 12006 -ne `wc -c <'co-meta.l'`; then
  449.     echo shar: \"'co-meta.l'\" unpacked with wrong size!
  450. fi
  451. # end of 'co-meta.l'
  452. fi
  453. if test -f 'defsys.l' -a "${1}" != "-c" ; then 
  454.   echo shar: Will not clobber existing file \"'defsys.l'\"
  455. else
  456. echo shar: Extracting \"'defsys.l'\" \(11775 characters\)
  457. sed "s/^X//" >'defsys.l' <<'END_OF_FILE'
  458. X;;;-*-Mode:LISP; Package:(PCL LISP 1000); Base:10; Syntax:Common-lisp -*-
  459. X;;;
  460. X;;; *************************************************************************
  461. X;;; Copyright (c) 1985, 1986, 1987 Xerox Corporation.  All rights reserved.
  462. X;;;
  463. X;;; Use and copying of this software and preparation of derivative works
  464. X;;; based upon this software are permitted.  Any distribution of this
  465. X;;; software or derivative works must comply with all applicable United
  466. X;;; States export control laws.
  467. X;;; 
  468. X;;; This software is made available AS IS, and Xerox Corporation makes no
  469. X;;; warranty about the software, its performance or its conformity to any
  470. X;;; specification.
  471. X;;; 
  472. X;;; Any person obtaining a copy of this software is requested to send their
  473. X;;; name and post office or electronic mail address to:
  474. X;;;   CommonLoops Coordinator
  475. X;;;   Xerox Artifical Intelligence Systems
  476. X;;;   2400 Hanover St.
  477. X;;;   Palo Alto, CA 94303
  478. X;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  479. X;;;
  480. X;;; Suggestions, comments and requests for improvements are also welcome.
  481. X;;; *************************************************************************
  482. X;;;
  483. X;;; Some support stuff for compiling and loading PCL.  It would be nice if
  484. X;;; there was some portable make-system we could all agree to share for a
  485. X;;; while.  At least until people really get databases and stuff.
  486. X;;;
  487. X;;; *** To install PCL at a new site, read the directions above the    ***
  488. X;;; *** second and third defvars in this file (down about 10 lines).  ***
  489. X;;;
  490. X
  491. X(in-package 'pcl :use (list (or (find-package 'walker)
  492. X                (make-package 'walker :use '(lisp)))
  493. X                'lisp))
  494. X
  495. X(defvar *pcl-system-date* "2/24/87")
  496. X
  497. X;;;
  498. X;;; Some CommonLisps have more symbols in the Lisp package than the ones that
  499. X;;; are explicitly specified in CLtL.  This causes trouble. Any Lisp that has
  500. X;;; extra symbols in the Lisp package should shadow those symbols in the PCL
  501. X;;; package.
  502. X;;;
  503. X#+TI
  504. X(shadow '(string-append once-only destructuring-bind
  505. X      memq assq delq neq ignore true false
  506. X      without-interrupts
  507. X      defmethod)
  508. X    'pcl)
  509. X#+Spice
  510. X(shadow '(memq assq delq) (find-package 'pcl))
  511. X#+Symbolics
  512. X(shadow '(ignore) (find-package 'pcl))
  513. X
  514. X;;;
  515. X;;; When installing PCL at your site, edit this defvar to give the directory
  516. X;;; in which the PCL files are stored.  The values given below are EXAMPLES
  517. X;;; of correct values for *pcl-pathname-defaults*.
  518. X;;; 
  519. X(defvar *pcl-pathname-defaults*
  520. X    #+Symbolics                (pathname "avalon:>Gregor>pcl>")
  521. X    #+SUN                      (pathname "/usr/yak/gregor/pcl/")
  522. X    #+ExCL                     (pathname "/usr/yak/gregor/pcl/")
  523. X    #+KCL                      (pathname "/user/isl/gregor/pcl/")
  524. X    #+(and DEC common vax VMS) (pathname "[gregor]")
  525. X    #+Spice                   (pathname "pcl:")
  526. X    #+HP                  (pathname "/net/hplfs2/users/kempf/public/pcl/")
  527. X    #+Xerox                    (pathname "{phylum}<pcl>")
  528. X    )
  529. X
  530. X;;;
  531. X;;; When you get a copy of PCL (by tape or by FTP), the sources files will
  532. X;;; have extensions of ".l" specifically, this file will be named defsys.l.
  533. X;;; The preferred way to install pcl is to rename these files to have the
  534. X;;; extension which your lisp likes to use for its files.  Alternately, it
  535. X;;; is possible not to rename the files.  If the files are not renamed to
  536. X;;; the proper convention, the second line of the following defvar should
  537. X;;; be changed to:
  538. X;;;     (let ((files-renamed-p nil)
  539. X;;;
  540. X;;; Note: Something people installing PCL on a machine running Unix
  541. X;;;       might find useful.  If you want to change the extensions
  542. X;;;       of the source files from ".l" to ".lsp", *all* you have to
  543. X;;;       do is the following:
  544. X;;;
  545. X;;;       % foreach i (*.l)
  546. X;;;       ? mv $i $i:r.lsp
  547. X;;;       ? end
  548. X;;;       %
  549. X;;;
  550. X;;;       I am sure that a lot of people already know that, and some
  551. X;;;       Unix hackers may say, "jeez who doesn't know that".  Those
  552. X;;;       same Unix hackers are invited to fix mv so that I can type
  553. X;;;       "mv *.l *.lsp".
  554. X;;;
  555. X(defvar *pathname-extensions*
  556. X    (let ((files-renamed-p t)
  557. X          (proper-extensions
  558. X        (car '(#+Symbolics           ("lisp"  . "bin")
  559. X               #+(and dec common)    ("LSP"   . "FAS")
  560. X               #+KCL                 ("lsp"   . "o")
  561. X               #+Xerox               ("lisp"  . "dfasl")
  562. X               #+(and Lucid MC68000) ("lisp"  . "lbin")
  563. X               #+(and Lucid VAX VMS) ("lisp"  . "vbin")
  564. X               #+excl                ("cl"    . "fasl")
  565. X               #+Spice               ("slisp" . "sfasl")
  566. X               #+HP                  ("l"     . "b")
  567. X               #+TI                  ("lisp"  . "xfasl")
  568. X               ))))
  569. X      (cond ((null proper-extensions) '("l" . "lbin"))
  570. X        ((null files-renamed-p) (cons "l" (cdr proper-extensions)))
  571. X        (t proper-extensions))))
  572. X
  573. X
  574. X
  575. X;;;
  576. X;;; *PCL-FILES* is a kind of "defsystem" for pcl.  A new port of pcl should
  577. X;;; add an entry for that port's xxx-low file.
  578. X;;; 
  579. X(defvar *pcl-files*
  580. X  (let ((xxx-low (or #+Symbolics '3600-low
  581. X             #+Lucid     'lucid-low
  582. X             #+Xerox     'Xerox-low
  583. X             #+TI        'ti-low
  584. X             #+(and dec common) 'vaxl-low
  585. X             #+KCL       'kcl-low
  586. X             #+excl      'excl-low
  587. X             #+Spice     'spice-low
  588. X             #+HP        'hp-low
  589. X             nil)))
  590. X    ;; file         load           compile         files which force
  591. X    ;;              environment    environment     recompilations of
  592. X    ;;                                             this file
  593. X    `(
  594. X      #+Symbolics
  595. X      (rel-7-patches nil            nil                    nil)
  596. X      #+Symbolics
  597. X      (walk         (rel-7-patches) (rel-7-patches)        nil)
  598. X      #-Symbolics
  599. X      (walk         nil             nil                    ())
  600. X      (macros       (walk)          (walk macros)          ())
  601. X      (low          (walk)          (macros)               (macros))
  602. X      (,xxx-low     (low)           (macros low)           ())
  603. X      (braid        t               ((braid :source))      (low ,xxx-low))
  604. X      (class-slots  t               (braid)                (low ,xxx-low))
  605. X      (defclass     t               (braid defclass)       (low ,xxx-low))
  606. X      (class-prot   t               (braid
  607. X                     defclass)             (low ,xxx-low))
  608. X      (methods      t               (braid
  609. X                     class-prot
  610. X                     (methods :source)    ;Because Common Lisp
  611. X                                ;makes it unlikely
  612. X                                ;that any particular
  613. X                                ;CommonLisp will do
  614. X                                ;the right thing with
  615. X                                ;a defsetf during
  616. X                                ;a compile-file.
  617. X                     )                  (low ,xxx-low))
  618. X      (dfun-templ   t               (methods 
  619. X                      (dfun-templ :source)) (low ,xxx-low))
  620. X      (fixup        t               (braid
  621. X                     methods
  622. X                     (fixup :source))   (low
  623. X                             ,xxx-low
  624. X                             braid
  625. X                             class-slots
  626. X                             defclass
  627. X                             class-prot
  628. X                             methods
  629. X                             dfun-templ))
  630. X      (high         (fixup)         ((high :source))    (low ,xxx-low walk))
  631. X      (compat       (high)          (high))
  632. X;     (meth-combi   (high)          (high)              )
  633. X;     (meth-combs   (meth-combi)    (meth-combi)        (meth-combi))
  634. X;     (trapd        (meth-combs)    (high)              )
  635. X      )))
  636. X
  637. X(defun load-pcl (&optional (sources-p nil))
  638. X  (load-system
  639. X    (if sources-p :sources :load) *pcl-files* *pcl-pathname-defaults*)
  640. X  (provide "pcl"))
  641. X
  642. X(defun compile-pcl (&optional (force-p nil))
  643. X  (load-system (if force-p ':force ':compile) *pcl-files* *pcl-pathname-defaults*))
  644. X
  645. X  ;;   
  646. X;;;;;; load-system
  647. X  ;;
  648. X;;; Yet Another Sort Of General System Facility and friends.
  649. X;;; 
  650. X
  651. X(defstruct (module (:constructor make-module
  652. X                 (name load-env comp-env recomp-reasons))
  653. X           (:print-function
  654. X             (lambda (m s d)
  655. X               (declare (ignore d))
  656. X               (format s
  657. X                   "#<Module ~A L:~@A  C:~@A  R:~@A>"
  658. X                   (module-name m)
  659. X                   (module-load-env m)
  660. X                   (module-comp-env m)
  661. X                   (module-recomp-reasons m)))))
  662. X  name
  663. X  load-env
  664. X  comp-env
  665. X  recomp-reasons)
  666. X
  667. X(defun load-system (mode system *default-pathname-defaults*)
  668. X  (#+Symbolics compiler:compiler-warnings-context-bind
  669. X   #-Symbolics progn
  670. X   (let ((loaded ())    ;A list of the modules loaded so far.
  671. X     (compiled ())  ;A list of the modules we have compiled.
  672. X     (modules ())   ;All the modules in the system.
  673. X     (module-names ())
  674. X     (*modules-to-source-load* ()))
  675. X     (declare (special *modules-to-source-load*))
  676. X     (labels
  677. X       (
  678. X       ;(load (x) x)
  679. X       ;(compile-file (x) x)
  680. X    (find-module (name)
  681. X      (or (car (member name modules :key #'module-name))
  682. X          (error "Can't find module of name ~S???" name)))
  683. X    (needs-compiling-p (m)
  684. X      (or (null (probe-file (make-binary-pathname (module-name m))))
  685. X          (eq (module-recomp-reasons m) 't)
  686. X          (dolist (r (module-recomp-reasons m))
  687. X        (when (member (find-module r) compiled)
  688. X          (return t)))
  689. X          (> (file-write-date (make-source-pathname (module-name m)))
  690. X         (file-write-date (make-binary-pathname (module-name m))))))
  691. X    (compile-module (m)
  692. X      (unless (member m compiled)
  693. X        (assure-compile-time-env m)
  694. X        (format t "~&Compiling ~A..." (module-name m))
  695. X        (compile-file (make-source-pathname (module-name m)))
  696. X        (push m compiled)))
  697. X    (load-module (m &optional source-p)
  698. X      (setq source-p (or (if (member m *modules-to-source-load*) t nil)
  699. X                 source-p
  700. X                 (eq mode :sources)))
  701. X      (unless (dolist (l loaded)
  702. X            (and (eq (car l) m)
  703. X             (eq (cdr l) source-p)
  704. X             (return t)))
  705. X        (assure-load-time-env m)
  706. X        (cond (source-p
  707. X           (format t "~&Loading source of ~A..." (module-name m))
  708. X           (load (make-source-pathname (module-name m))))
  709. X          (t
  710. X           (format t "~&Loading ~A..." (module-name m))
  711. X           (load (make-binary-pathname (module-name m)))))
  712. X        (push (cons m source-p) loaded)))
  713. X    (assure-compile-time-env (m)
  714. X      (let ((*modules-to-source-load*
  715. X          (cons m *modules-to-source-load*)))
  716. X        (declare (special *modules-to-source-load*))    ;Should not have to
  717. X                        ;but...
  718. X        (dolist (c (module-comp-env m))
  719. X          (when (eq (cadr c) :source)
  720. X        (push (find-module (car c)) *modules-to-source-load*)))
  721. X        (dolist (c (module-comp-env m))
  722. X          (load-module (find-module (car c))))))
  723. X    (assure-load-time-env (m)
  724. X      (dolist (l (module-load-env m))
  725. X        (load-module (find-module l))))
  726. X    )
  727. X       
  728. X       ;; Start by converting the list representation of we got into
  729. X       ;; modules.  At the same time, we convert the abbreviations
  730. X       ;; for load-envs and comp envs to the unabbreviated internal
  731. X       ;; representation.
  732. X       (dolist (file system)
  733. X     (let ((name (car file))
  734. X           (load-env (cadr file))
  735. X           (comp-env (caddr file))
  736. X           (recomp-reasons (cadddr file)))
  737. X       (push (make-module name
  738. X                  (if (eq load-env 't)
  739. X                  (reverse module-names)
  740. X                  load-env)
  741. X                  (mapcar #'(lambda (c)
  742. X                      (if (listp c)
  743. X                          c
  744. X                          (list c :binary)))
  745. X                      (if (eq comp-env 't)
  746. X                      (reverse (cons name module-names))
  747. X                      comp-env))
  748. X                  recomp-reasons)
  749. X         modules)
  750. X       (push name module-names)))
  751. X       (setq modules (nreverse modules))
  752. X       (ecase mode
  753. X     (:compile
  754. X       (dolist (module modules)
  755. X         (when (needs-compiling-p module)
  756. X           (compile-module module))))
  757. X     (:force
  758. X       (dolist (module modules)
  759. X         (compile-module module)))
  760. X     (:load
  761. X       (dolist (module modules)
  762. X         (load-module module)))
  763. X     (:sources
  764. X       (dolist (module modules)
  765. X         (load-module module t))))))))
  766. X
  767. X(defun make-source-pathname (name)
  768. X  (make-pathname
  769. X    :name #-VMS (string-downcase (string name))
  770. X          #+VMS (string-downcase (substitute #\_ #\- (string name)))
  771. X    :type (car *pathname-extensions*)
  772. X    :defaults *default-pathname-defaults*))
  773. X
  774. X(defun make-binary-pathname (name)
  775. X  (make-pathname
  776. X    :name #-VMS (string-downcase (string name))
  777. X          #+VMS (string-downcase (substitute #\_ #\- (string name)))
  778. X    :type (cdr *pathname-extensions*)
  779. X    :defaults *default-pathname-defaults*))
  780. X
  781. END_OF_FILE
  782. if test 11775 -ne `wc -c <'defsys.l'`; then
  783.     echo shar: \"'defsys.l'\" unpacked with wrong size!
  784. fi
  785. # end of 'defsys.l'
  786. fi
  787. if test -f 'fixup.l' -a "${1}" != "-c" ; then 
  788.   echo shar: Will not clobber existing file \"'fixup.l'\"
  789. else
  790. echo shar: Extracting \"'fixup.l'\" \(12761 characters\)
  791. sed "s/^X//" >'fixup.l' <<'END_OF_FILE'
  792. X;;;-*-Mode:LISP; Package: PCL; Base:10; Syntax:Common-lisp; Patch-File: Yes -*-
  793. X;;;
  794. X;;; *************************************************************************
  795. X;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  796. X;;;
  797. X;;; Use and copying of this software and preparation of derivative works
  798. X;;; based upon this software are permitted.  Any distribution of this
  799. X;;; software or derivative works must comply with all applicable United
  800. X;;; States export control laws.
  801. X;;; 
  802. X;;; This software is made available AS IS, and Xerox Corporation makes no
  803. X;;; warranty about the software, its performance or its conformity to any
  804. X;;; specification.
  805. X;;; 
  806. X;;; Any person obtaining a copy of this software is requested to send their
  807. X;;; name and post office or electronic mail address to:
  808. X;;;   CommonLoops Coordinator
  809. X;;;   Xerox Artifical Intelligence Systems
  810. X;;;   2400 Hanover St.
  811. X;;;   Palo Alto, CA 94303
  812. X;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  813. X;;;
  814. X;;; Suggestions, comments and requests for improvements are also welcome.
  815. X;;; *************************************************************************
  816. X;;;
  817. X
  818. X(in-package 'pcl)
  819. X
  820. X(eval-when (compile load eval)
  821. X  (setq *real-methods-exist-p* nil)
  822. X  (setf (symbol-function 'expand-defmeth)
  823. X    (symbol-function 'real-expand-defmeth)))
  824. X
  825. X(eval-when (load)
  826. X  (clrhash *discriminator-name-hash-table*)
  827. X  (fix-early-defmeths)
  828. X ;; This now happens at the end of loading HIGH to make it
  829. X ;; possible to compile and load pcl in the same environment.
  830. X ;(setq *error-when-defining-method-on-existing-function* t)
  831. X  )
  832. X
  833. X(eval-when (compile load eval)
  834. X  (setq *real-methods-exist-p* t))
  835. X
  836. X  ;;   
  837. X;;;;;; Pending defmeths which I couldn't do before.
  838. X  ;;
  839. X
  840. X
  841. X(eval-when (load eval)
  842. X  (setf (discriminator-named 'print-instance) ())
  843. X  (make-specializable 'print-instance :arglist '(instance stream depth)))
  844. X
  845. X(defmeth print-instance ((instance object) stream depth)
  846. X  (let ((length (if (numberp *print-length*) (* *print-length* 2) nil)))
  847. X    (format stream "#S(~S" (class-name (class-of instance)))
  848. X    (iterate ((slot-or-value in (all-slots instance))
  849. X          (slotp = t (not slotp)))
  850. X      (when (numberp length)
  851. X    (cond ((<= length 0) (format stream " ...") (return ()))
  852. X          (t (decf length))))
  853. X      (princ " " stream)
  854. X      (let ((*print-level* (cond ((null *print-level*) ())
  855. X                 (slotp 1)
  856. X                 (t (- *print-level* depth)))))
  857. X    (if (and *print-level* (<= *print-level* 0))
  858. X        (princ "#" stream)
  859. X        (prin1 slot-or-value stream))))
  860. X    (princ ")" stream)))
  861. X
  862. X(defmeth print-instance ((class essential-class) stream depth)
  863. X  (named-object-print-function class stream depth))
  864. X
  865. X
  866. X(defmethod print-instance ((method essential-method) stream depth)
  867. X  (ignore depth)
  868. X  (printing-random-thing (method stream)
  869. X    (let ((discriminator (method-discriminator method))
  870. X      (class-name (capitalize-words (class-name (class-of method)))))
  871. X      (format stream "~A ~S ~:S"
  872. X          class-name
  873. X          (and discriminator (discriminator-name discriminator))
  874. X          (method-type-specifiers method)))))
  875. X
  876. X(defmethod print-instance ((method basic-method) stream depth)
  877. X  (ignore depth)
  878. X  (printing-random-thing (method stream)
  879. X    (let ((discriminator (method-discriminator method))
  880. X      (class-name (capitalize-words (class-name (class-of method)))))
  881. X      (format stream "~A ~S ~:S"
  882. X          class-name
  883. X          (and discriminator (discriminator-name discriminator))
  884. X          (unparse-type-specifiers method)))))
  885. X
  886. X(defmethod print-instance ((discriminator essential-discriminator) stream depth)
  887. X  (named-object-print-function discriminator stream depth))
  888. X
  889. X(defmethod print-instance ((discriminator basic-discriminator) stream depth)
  890. X  (named-object-print-function
  891. X    discriminator stream depth (list (method-combination-type discriminator))))
  892. X
  893. X(eval-when (load)
  894. X
  895. X(define-meta-class essential-class (lambda (x) (%instance-ref x 0)))
  896. X
  897. X(defmeth class-slots ((class essential-class))
  898. X  (ignore class)
  899. X  ())
  900. X
  901. X(defmeth make-instance ((class essential-class))
  902. X  (let ((primitive-instance
  903. X      (%make-instance (class-named 'esfiers method)))))
  904. X
  905. X(defmethod print-instance ((mss))))))
  906. X    (setf (%instance-ref primitive-instance 0) class)
  907. X    primitive-instance))
  908. X
  909. X(defmeth get-slot-using-class ((class essential-class) object slot-name)
  910. X  (let ((pos (position slot-name (class-slots class) :key #'slotd-name)))
  911. X    (if pos
  912. X    (%instance-ref object (1+ pos))
  913. X    (slot-missing ;class
  914. X      object slot-name))))
  915. X
  916. X(defmeth put-slot-using-class ((class essential-class)
  917. X                   object
  918. X                   slot-name
  919. X                   new-value)
  920. X  (let ((pos (position slot-name (class-slots class) :key #'slotd-name)))
  921. X    (if pos
  922. X    (setf (%instance-ref object (1+ pos)) new-value)
  923. X    (slot-missing ;class
  924. X              object slot-name))))
  925. X
  926. X(defmeth optimize-get-slot (class form)
  927. X  (declare (ignore class))
  928. X  form)
  929. X
  930. X(defmeth optimize-setf-of-get-slot (class form)
  931. X  (declare (ignore class))
  932. X  form)
  933. X
  934. X(defmeth make-slotd ((class essential-class) &rest keywords-and-options)
  935. X  (ignore class)
  936. X  (apply #'make-slotd--essential-class keywords-and-options))
  937. X
  938. X(defmeth add-named-class ((proto-class essential-class) name
  939. X              local-supers
  940. X              local-slot-slotds
  941. X              extra)
  942. X  ;; First find out if there is already a class with this name.
  943. X  ;; If there is, call class-for-redefinition to get the class
  944. X  ;; object to use for the new definition.  If there is no exisiting
  945. X  ;; class we just make a new instance.
  946. X  (let* ((existing (class-named name t))
  947. X     (class (if existing
  948. X            (class-for-redefinition existing proto-class name 
  949. X                        local-supers local-slot-slotds
  950. X                        extra)
  951. X            (make (class-of proto-class)))))
  952. X
  953. X    (setq local-supers
  954. X      (mapcar
  955. X        #'(lambda (ls)
  956. X        (or (class-named ls t)
  957. X            (error "~S was specified as the name of a local-super~%~
  958. X                            for the class named ~S.  But there is no class~%~
  959. X                            class named ~S." ls name ls)))
  960. X        local-supers))
  961. X    
  962. X    (setf (class-name class) name)
  963. X;   (setf (class-ds-options class) extra)    ;This is NOT part of the
  964. X;                        ;standard protocol.
  965. X   
  966. X    (add-class class local-supers local-slot-slotds extra)
  967. X    
  968. X    (setf (class-named name) class)
  969. X    name))
  970. X
  971. X(defmeth supers-changed ((class essential-class)
  972. X             old-local-supers
  973. X             old-local-slots
  974. X             extra
  975. X             top-p)
  976. X  (ignore old-local-supers old-local-slots top-p)
  977. X  (let ((cpl (compute-class-precedence-list class)))
  978. X    (setf (class-class-precedence-list class) cpl)
  979. X;   (update-slots--class class cpl)                 ;This is NOT part of
  980. X;                                 ;the essential-class
  981. X;                                 ;protocol.
  982. X    (dolist (sub-class (class-direct-subclasses class))
  983. X      (supers-changed sub-class
  984. X              (class-local-supers sub-class)
  985. X              (class-local-slots sub-class)
  986. X              extra
  987. X              nil))
  988. X;   (when top-p                                          ;This is NOT part of
  989. X;     (update-method-inheritance class old-local-supers));the essential-class
  990. X;                                      ;protocol.
  991. X    ))
  992. X
  993. X(defmeth slots-changed ((class essential-class)
  994. X            old-local-slots
  995. X            extra
  996. X            top-p)
  997. X  (ignore top-p old-local-slots)
  998. X  ;; When this is called, class should have its local-supers and
  999. X  ;; local-slots slots filled in properly.
  1000. X; (update-slots--class class (class-class-precedence-list class))
  1001. X  (dolist (sub-class (class-direct-subclasses class))
  1002. X    (slots-changed sub-class (class-local-slots sub-class) extra nil)))
  1003. X
  1004. X(defmeth method-equal (method argument-specifiers options)
  1005. X  (ignore options)
  1006. X  (equal argument-specifiers (method-type-specifiers method)))
  1007. X
  1008. X(defmeth methods-combine-p ((d essential-discriminator))
  1009. X  (ignore d)
  1010. X  nil)
  1011. X
  1012. X)
  1013. X
  1014. X  ;;   
  1015. X;;;;;; 
  1016. X  ;;
  1017. X
  1018. X(define-method-body-macro call-next-method ()
  1019. X  :global :error
  1020. X  :method (expand-call-next-method
  1021. X        (macroexpand-time-method macroexpand-time-environment)
  1022. X        nil
  1023. X        macroexpand-time-environment))
  1024. X
  1025. X(defmethod expand-call-next-method ((mex-method method) args mti)
  1026. X  (ignore args)
  1027. X  (let* ((arglist (and mex-method (method-arglist mex-method)))
  1028. X     (uid (macroexpand-time-method-uid mti))
  1029. X     (load-method-1-args (macroexpand-time-load-method-1-args mti))
  1030. X     (load-time-eval-form `(load-time-eval
  1031. X                 (if (boundp ',uid)
  1032. X                     ,uid
  1033. X                     (setq ,uid
  1034. X                       (apply #'load-method-1
  1035. X                          ',load-method-1-args)))))
  1036. X     (applyp nil))
  1037. X    (multiple-value-setq (arglist applyp) (make-call-arguments arglist))
  1038. X    (cond ((null (method-type-specifiers mex-method))
  1039. X       (warn "Using call-next-method in a default method.~%~
  1040. X                  At run time this will generate an error.")
  1041. X       '(error "Using call-next-method in a default method."))
  1042. X      (applyp
  1043. X       `(apply
  1044. X          #'call-next-method-internal ,load-time-eval-form . ,arglist))
  1045. X      (t
  1046. X       `(call-next-method-internal ,load-time-eval-form . ,arglist)))))
  1047. X
  1048. X(defun call-next-method-internal (current-method &rest args)
  1049. X  (let* ((discriminator (method-discriminator current-method))
  1050. X     (type-specifiers (method-type-specifiers current-method))
  1051. X     (most-specific nil)
  1052. X     (most-specific-type-specifiers ())
  1053. X     (dispatch-order (get-slot--class discriminator 'dispatch-order)))
  1054. X    (iterate ((method in (discriminator-methods discriminator)))
  1055. X      (let ((method-type-specifiers (method-type-specifiers method))
  1056. X            (temp ()))
  1057. X        (and (every #'(lambda (arg type-spec)
  1058. X            (or (eq type-spec 't)
  1059. X                (memq type-spec
  1060. X                  (get-slot--class
  1061. X                    (class-of arg) 'class-precedence-list))))
  1062. X                    args method-type-specifiers)
  1063. X             (eql 1 (setq temp (compare-type-specifier-lists
  1064. X                 type-specifiers
  1065. X                 method-type-specifiers
  1066. X                 ()
  1067. X                 args
  1068. X                 ()
  1069. X                 dispatch-order)))
  1070. X             (or (null most-specific)
  1071. X                 (eql 1 (setq temp (compare-type-specifier-lists
  1072. X                                     method-type-specifiers
  1073. X                                     most-specific-type-specifiers
  1074. X                                     ()
  1075. X                                     args
  1076. X                                     ()
  1077. X                     dispatch-order))))
  1078. X             (setq most-specific method
  1079. X                   most-specific-type-specifiers method-type-specifiers))))
  1080. X    (if (or most-specific
  1081. X            (setq most-specific (discriminator-default-method
  1082. X                  discriminator)))
  1083. X        (apply (method-function most-specific) args)
  1084. X        (error "no super method found"))))
  1085. X
  1086. X;;;
  1087. X;;; This is kind of bozoid because it always copies the lambda-list even
  1088. X;;; when it doesn't need to.  It also doesn't remember things it could
  1089. X;;; remember, causing it to call memq more than it should.  Fix this one
  1090. X;;; day when there is nothing else to do.
  1091. X;;; 
  1092. X(defun make-call-arguments (lambda-list &aux applyp)
  1093. X  (setq lambda-list (reverse lambda-list))
  1094. X  (when (memq '&aux lambda-list)
  1095. X    (setq lambda-list (cdr (memq '&aux lambda-list))))
  1096. X  (setq lambda-list (nreverse lambda-list))
  1097. X  (let ((optional (memq '&optional lambda-list)))
  1098. X    (when optional
  1099. X      ;; The &optional keyword appears in the lambda list.
  1100. X      ;; Get rid of it, by moving the rest of the lambda list
  1101. X      ;; up, then go through the optional arguments, replacing
  1102. X      ;; them with the real symbol.
  1103. X      (setf (car optional) (cadr optional)
  1104. X        (cdr optional) (cddr optional))
  1105. X      (iterate ((loc on optional))
  1106. X    (when (memq (car loc) lambda-list-keywords)
  1107. X      (unless (memq (car loc) '(&rest &key &allow-other-keys))
  1108. X        (error
  1109. X          "The non-standard lambda list keyword ~S appeared in the~%~
  1110. X               lambda list of a method in which CALL-NEXT-METHOD is used.~%~
  1111. X               PCL can only deal with standard lambda list keywords."))
  1112. X      (when (listp (car loc)) (setf (car loc) (caar loc)))))))
  1113. X  (let ((rest (memq '&rest lambda-list)))
  1114. X    (cond ((not (null rest))
  1115. X       ;; &rest appears in the lambda list. This means we
  1116. X       ;; have to do an apply. We ignore the rest of the
  1117. X       ;; lambda list, just grab the &rest var and set applyp.
  1118. X       (setf (car rest) (if (listp (cadr rest))
  1119. X                (caadr rest)
  1120. X                (cadr rest))
  1121. X         (cdr rest) ())
  1122. X       (setq applyp t))
  1123. X      (t
  1124. X       (let ((key (memq '&key lambda-list)))
  1125. X         (when key
  1126. X           ;; &key appears in the lambda list.  Remove &key from the
  1127. X           ;; lambda list then replace all the keywords with pairs of
  1128. X           ;; the actual keyword followed by the value variable.
  1129. X           ;; Have to parse the hairy triple case of &key.
  1130. X           (let ((key-args
  1131. X               (iterate ((arg in (cdr key)))
  1132. X             (until (eq arg '&allow-other-keys))
  1133. X             (cond ((symbolp arg)
  1134. X                (collect (make-keyword arg))
  1135. X                (collect arg))
  1136. X                   ((cddr arg)
  1137. X                (collect (caddr arg))
  1138. X                (collect (car arg)))
  1139. X                   (t
  1140. X                (collect (make-keyword (car arg)))
  1141. X                (collect (car arg)))))))
  1142. X         (if key-args
  1143. X             (setf (car key) (car key-args)
  1144. X               (cdr key) (cdr key-args))
  1145. X             (setf (cdr key) nil
  1146. X               lambda-list (remove '&key lambda-list)))))))))
  1147. X  (values lambda-list applyp))
  1148. X
  1149. END_OF_FILE
  1150. if test 12761 -ne `wc -c <'fixup.l'`; then
  1151.     echo shar: \"'fixup.l'\" unpacked with wrong size!
  1152. fi
  1153. # end of 'fixup.l'
  1154. fi
  1155. if test -f 'high.l' -a "${1}" != "-c" ; then 
  1156.   echo shar: Will not clobber existing file \"'high.l'\"
  1157. else
  1158. echo shar: Extracting \"'high.l'\" \(9615 characters\)
  1159. sed "s/^X//" >'high.l' <<'END_OF_FILE'
  1160. X;;;-*-Mode:LISP; Package:(PCL (LISP WALKER)); Base:10; Syntax:Common-lisp -*-
  1161. X;;;
  1162. X;;; *************************************************************************
  1163. X;;; Copyright (c) 1985 Xerox Corporation.  All rights reserved.
  1164. X;;;
  1165. X;;; Use and copying of this software and preparation of derivative works
  1166. X;;; based upon this software are permitted.  Any distribution of this
  1167. X;;; software or derivative works must comply with all applicable United
  1168. X;;; States export control laws.
  1169. X;;; 
  1170. X;;; This software is made available AS IS, and Xerox Corporation makes no
  1171. X;;; warranty about the software, its performance or its conformity to any
  1172. X;;; specification.
  1173. X;;; 
  1174. X;;; Any person obtaining a copy of this software is requested to send their
  1175. X;;; name and post office or electronic mail address to:
  1176. X;;;   CommonLoops Coordinator
  1177. X;;;   Xerox Artifical Intelligence Systems
  1178. X;;;   2400 Hanover St.
  1179. X;;;   Palo Alto, CA 94303
  1180. X;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
  1181. X;;;
  1182. X;;; Suggestions, comments and requests for improvements are also welcome.
  1183. X;;; *************************************************************************
  1184. X;;;
  1185. X;;; Non-Bootstrap stuff
  1186. X;;;
  1187. X
  1188. X(in-package 'pcl :nicknames '(portable-commonloops))
  1189. X
  1190. X
  1191. X(ndefstruct (obsolete-class (:class class)
  1192. X                            (:include (class))))
  1193. X
  1194. X
  1195. X(defmeth get-slot-using-class ((class obsolete-class)
  1196. X                   object slot-name
  1197. X                   dont-call-slot-missing-p
  1198. X                   default)
  1199. X  (change-class object
  1200. X        (cadr (get-slot class 'class-precedence-list)))
  1201. X  (get-slot-using-class
  1202. X    (class-of object) object slot-name dont-call-slot-missing-p default))
  1203. X
  1204. X
  1205. X  ;;   
  1206. X;;;;;; 
  1207. X  ;;   
  1208. X
  1209. X
  1210. X(defmeth describe-class (class-or-class-name
  1211. X              &optional (stream *standard-output*))
  1212. X  (flet ((pretty-class (class) (or (class-name class) class)))
  1213. X    (if (symbolp class-or-class-name)
  1214. X    (describe-class (class-named class-or-class-name) stream)
  1215. X    (let ((class class-or-class-name))
  1216. X      (format stream
  1217. X          "~&The class ~S is an instance of class ~S."
  1218. X          class
  1219. X          (class-of class))
  1220. X      (format stream "~&Name:~23T~S~%~
  1221. X                Class-Precedence-List:~23T~S~%~
  1222. X                            Local-Supers:~23T~S~%~
  1223. X                            Direct-Subclasses:~23T~S"
  1224. X          (class-name class)
  1225. X          (mapcar #'pretty-class (class-class-precedence-list class))
  1226. X          (mapcar #'pretty-class (class-local-supers class))
  1227. X          (mapcar #'pretty-class (class-direct-subclasses class)))
  1228. X      class))))
  1229. X
  1230. X(defun describe-instance (object &optional (stream t))
  1231. X  (let* ((class (class-of object))
  1232. X         (instance-slots (class-instance-slots class))
  1233. X         (non-instance-slots (class-non-instance-slots class))
  1234. X         (dynamic-slots (iwmc-class-dynamic-slots object))
  1235. X     (max-slot-name-length 0))
  1236. X    (macrolet ((adjust-slot-name-length (name)
  1237. X         `(setq max-slot-name-length
  1238. X            (max max-slot-name-length
  1239. X                 (length (the string (symbol-name ,name))))))
  1240. X           (describe-slot (name value &optional (allocation () alloc-p))
  1241. X         (if alloc-p
  1242. X             `(format stream
  1243. X                  "~% ~A ~S ~VT  ~S"
  1244. X                  ,name ,allocation (+ max-slot-name-length 7)
  1245. X                  ,value)
  1246. X             `(format stream
  1247. X                  "~% ~A~VT  ~S"
  1248. X                  ,name max-slot-name-length ,value))))
  1249. X      ;; Figure out a good width for the slot-name column.
  1250. X      (iterate ((slotd in instance-slots))
  1251. X    (adjust-slot-name-length (slotd-name slotd)))      
  1252. X      (iterate ((slotd in non-instance-slots))
  1253. X    (adjust-slot-name-length (slotd-name slotd)))
  1254. X      (iterate ((name in dynamic-slots by cddr))
  1255. X    (adjust-slot-name-length name))
  1256. X      (setq max-slot-name-length  (min (+ max-slot-name-length 3) 30))
  1257. X      (format stream "~%~S is an instance of class ~S:" object class)
  1258. X      (format stream "~% The following slots are allocated in the instance ~
  1259. X                         (:INSTANCE allocation):")
  1260. X      (iterate ((slotd in instance-slots))
  1261. X    (let ((name (slotd-name slotd)))
  1262. X      (describe-slot name (get-slot object name))))
  1263. X      (when (or dynamic-slots
  1264. X        (iterate ((slotd in non-instance-slots))
  1265. X          (when (neq (slotd-allocation slotd) :dynamic) (return t))))
  1266. X    (format stream
  1267. X        "~%The following slots have special allocations as shown:")
  1268. X    (iterate ((slotd in non-instance-slots))
  1269. X      (unless (eq (slotd-allocation slotd) :dynamic)
  1270. X        (describe-slot (slotd-name slotd)
  1271. X               (get-slot object (slotd-name slotd))
  1272. X               (slotd-allocation slotd))))
  1273. X    (iterate ((name in dynamic-slots by cddr)
  1274. X          (val in (cdr dynamic-slots) by cddr))
  1275. X      (describe-slot name val :dynamic)))))
  1276. X  object)
  1277. X
  1278. X
  1279. X  ;;   
  1280. X;;;;;; 
  1281. X  ;;   
  1282. X
  1283. X(ndefstruct (structure-metaclass (:class class)
  1284. X                 (:include class)
  1285. X                 (:constructor nil)))
  1286. X
  1287. X(defmeth expand-defstruct ((class structure-metaclass)
  1288. X               name-and-options doc slot-descriptions)
  1289. X  (ignore class doc)
  1290. X  (let ((class-argument (iterate ((option in (cdr name-and-options)))
  1291. X                 (when (and (listp option)
  1292. X                        (eq (car option) ':class))
  1293. X                   (return option)))))
  1294. X    `(defstruct ,(remove class-argument name-and-options)
  1295. X       . ,slot-descriptions)))
  1296. X
  1297. X
  1298. X  ;;   
  1299. X;;;;;; 
  1300. X  ;;   
  1301. X
  1302. X(eval-when (compile load eval)
  1303. X(ndefstruct (built-in (:class class)
  1304. X              (:include (class))))
  1305. X
  1306. X(ndefstruct (built-in-with-fast-type-predicate (:class class)
  1307. X                           (:include (built-in))))
  1308. X
  1309. X(defmacro define-built-in-class (name includes &optional fast-type-predicate)
  1310. X  `(ndefstruct (,name (:class ,(if fast-type-predicate
  1311. X                   'built-in-with-fast-type-predicate
  1312. X                   'built-in))
  1313. X              (:include ,includes))
  1314. X     (fast-type-predicate ',fast-type-predicate)  ;;;
  1315. X
  1316. X     ))
  1317. X
  1318. X(defmeth parse-defstruct-options ((class built-in) name options)
  1319. X  (let ((ds-options (call-next-method)))
  1320. X    (or (ds-options-includes ds-options)
  1321. X    (setf (ds-options-includes ds-options) (list 'object)))
  1322. X    ds-options))
  1323. X
  1324. X(defmeth expand-defstruct-make-definitions ((class built-in)
  1325. X                        name ds-options slotds)
  1326. X  (ignore class name ds-options slotds)
  1327. X  ())
  1328. X
  1329. X(defmeth make-instance ((class built-in))
  1330. X  (ignore class)
  1331. X  (error
  1332. X    "Attempt to make an instance of the built-in class ~S.~%~
  1333. X     Currently it is not possible to make instance of built-in classes with~
  1334. X     make.~%~
  1335. X     A design for this exists, because of metaclasses it is easy to do,~%~
  1336. X     it just has to be done."
  1337. X    class))
  1338. X
  1339. X(defmeth compatible-meta-class-change-p
  1340. X     ((from built-in)
  1341. X      (to built-in-with-fast-type-predicate))
  1342. X  (ignore from to)
  1343. X  t)
  1344. X
  1345. X(defmeth check-super-metaclass-compatibility ((built-in built-in)
  1346. X                           (new-super class))
  1347. X  (or (eq new-super (class-named 't))
  1348. X      (error "~S cannot have ~S as a super.~%~
  1349. X              The only meta-class CLASS class that a built-in class can~%~
  1350. X              have as a super is the class T."
  1351. X         built-in new-super)))
  1352. X
  1353. X
  1354. X
  1355. X(defmeth check-super-metaclass-compatibility
  1356. X     ((class built-in)
  1357. X      (new-local-super built-in))
  1358. X  (ignore class new-local-super)
  1359. X  t)
  1360. X
  1361. X;(defmeth check-super-metaclass-compatibility
  1362. X;     ((class built-in-with-fast-type-predicate)
  1363. X;      (new-local-super built-in))
  1364. X;  (ignore class new-local-super)
  1365. X;  t)
  1366. X
  1367. X(defmeth compute-class-precedence-list ((class built-in))
  1368. X  ;; Compute the class-precedence list just like we do for CLASS except that
  1369. X  ;; a built-in class cannot inherit COMMON from another built-in class.  But
  1370. X  ;; it does inherit the things that it would have inherited had it inherited
  1371. X  ;; common.
  1372. X  (let ((val (call-next-method))
  1373. X    (common-class nil))
  1374. X    (if (not (memq (setq common-class (class-named 'common t))
  1375. X           (class-local-supers class)))
  1376. X    (remove common-class val)
  1377. X    val)))
  1378. X
  1379. X
  1380. X)
  1381. X
  1382. X  ;;   
  1383. X;;;;;; The built in types 
  1384. X  ;;   
  1385. X
  1386. X(define-built-in-class common (t))
  1387. X
  1388. X(define-built-in-class pathname (common) pathnamep)
  1389. X
  1390. X(define-built-in-class stream (common) streamp)
  1391. X
  1392. X(define-built-in-class sequence (t))
  1393. X(define-built-in-class list (sequence) listp)
  1394. X(define-built-in-class cons (list common) consp)
  1395. X(define-built-in-class symbol (common) symbolp)
  1396. X(define-built-in-class null (list symbol) null)
  1397. X
  1398. X(define-built-in-class keyword (symbol common) keywordp)
  1399. X
  1400. X(define-built-in-class array (common) arrayp)
  1401. X(define-built-in-class vector (sequence array) vectorp)
  1402. X(define-built-in-class simple-array (array))
  1403. X
  1404. X(define-built-in-class string (vector common) stringp)
  1405. X(define-built-in-class bit-vector (vector) bit-vector-p)
  1406. X;(vector t) should go here
  1407. X
  1408. X(define-built-in-class simple-string (string simple-array) simple-string-p)
  1409. X(define-built-in-class simple-bit-vector (bit-vector simple-array)
  1410. X                     simple-bit-vector-p)
  1411. X(define-built-in-class simple-vector (vector simple-array) simple-vector-p)
  1412. X
  1413. X(define-built-in-class function (t))
  1414. X
  1415. X(define-built-in-class character (t) characterp)
  1416. X(define-built-in-class string-char (character) string-char-p)
  1417. X(define-built-in-class standard-char (string-char common) standard-char-p)
  1418. X
  1419. X(define-built-in-class structure (common))
  1420. X
  1421. X(define-built-in-class number (t) numberp)
  1422. X
  1423. X(define-built-in-class rational (number) rationalp)
  1424. X(define-built-in-class float (number) floatp)
  1425. X(define-built-in-class complex (number common) complexp)
  1426. X
  1427. X(define-built-in-class integer (rational))
  1428. X(define-built-in-class ratio   (rational common))
  1429. X
  1430. X(define-built-in-class fixnum (integer common))
  1431. X(define-built-in-class bignum (integer common))
  1432. X
  1433. X(define-built-in-class short-float  (float common))
  1434. X(define-built-in-class single-float (float common))
  1435. X(define-built-in-class double-float (float common))
  1436. X(define-built-in-class long-float   (float common))
  1437. X
  1438. X(define-built-in-class hash-table (common) hash-table-p)
  1439. X(define-built-in-class readtable (common) readtablep)
  1440. X(define-built-in-class package (common) packagep)
  1441. X(define-built-in-class random-state (common) random-state-p)
  1442. X
  1443. X
  1444. X(eval-when (load)
  1445. X  (setq *error-when-defining-method-on-existing-function* t))
  1446. X
  1447. END_OF_FILE
  1448. if test 9615 -ne `wc -c <'high.l'`; then
  1449.     echo shar: \"'high.l'\" unpacked with wrong size!
  1450. fi
  1451. # end of 'high.l'
  1452. fi
  1453. echo shar: End of archive 3 \(of 13\).
  1454. cp /dev/null ark3isdone
  1455. MISSING=""
  1456. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  1457.     if test ! -f ark${I}isdone ; then
  1458.     MISSING="${MISSING} ${I}"
  1459.     fi
  1460. done
  1461. if test "${MISSING}" = "" ; then
  1462.     echo You have unpacked all 13 archives.
  1463.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1464. else
  1465.     echo You still need to unpack the following archives:
  1466.     echo "        " ${MISSING}
  1467. fi
  1468. ##  End of shell archive.
  1469. exit 0
  1470. -- 
  1471.  
  1472. Rich $alz            "Anger is an energy"
  1473. Cronus Project, BBN Labs    rsalz@bbn.com
  1474. Moderator, comp.sources.unix    sources@uunet.uu.net
  1475.